package com.wish.group05.finance.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wish.group05.base.dto.CwPaymentPlanDto;
import com.wish.group05.base.dto.ResponsePayManageDto;
import com.wish.group05.base.entity.CwPaymentPlan;
import com.wish.group05.base.entity.SfContract;
import com.wish.group05.base.service.ICwPaymentPlanService;
import com.wish.group05.base.service.ISfContractService;
import com.wish.group05.common.security.service.TokenService;
import com.wish.group05.system.api.RemoteDictDataService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wish.group05.common.log.annotation.Log;
import com.wish.group05.common.log.enums.BusinessType;
import com.wish.group05.common.security.annotation.PreAuthorize;
import com.wish.group05.common.core.web.controller.BaseController;
import com.wish.group05.common.core.web.domain.AjaxResult;
import com.wish.group05.common.core.utils.poi.ExcelUtil;
import com.wish.group05.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author wish
 * @date 2022-06-05
 */
@RestController
@RequestMapping("/paymentplan")
public class TCwPaymentPlanController extends BaseController
{
    @Autowired
    ICwPaymentPlanService cwPaymentPlanService;
    @Resource
    RemoteDictDataService remoteDictDataService;
    @Autowired
    ISfContractService sfContractService;
    @Autowired
    TokenService tokenService;

    /**
     * 修改付款
     * @param cwPaymentPlanDto
     * @return
     */
    @PostMapping("updatePayment")
    public AjaxResult updatePayment(@RequestBody CwPaymentPlanDto cwPaymentPlanDto) {
        //修改数据
        CwPaymentPlan cwPaymentPlan = cwPaymentPlanService.getById(cwPaymentPlanDto.getId());
        cwPaymentPlan.setId(cwPaymentPlanDto.getId());
        cwPaymentPlan.setPayMethod(cwPaymentPlanDto.getPayMethod());
        cwPaymentPlan.setPayState(2);
        cwPaymentPlan.setPaidTime(new Date());
        cwPaymentPlan.setRealPaymentAmount(cwPaymentPlan.getPaymentAmount());
        cwPaymentPlan.setUpdateTime(new Date());
        cwPaymentPlan.setUpdateUserid(tokenService.getLoginUser().getUserid());
        cwPaymentPlanService.saveOrUpdate(cwPaymentPlan);
        return AjaxResult.success();
    }

    /**
     * 获取字典表数据
     * @return
     */
    @GetMapping("getDict")
    public AjaxResult getDict() {
        HashMap<String, Object> map = new HashMap<>();
        //付款状态
        AjaxResult payState = remoteDictDataService.getDictDataList("sys_pay_state");
        map.put("payStateList",payState);
        AjaxResult billType = remoteDictDataService.getDictDataList("payment_bill_type");
        map.put("billTypeList",billType);
        AjaxResult payMothodList = remoteDictDataService.getDictDataList("sys_pay_method");
        map.put("payMethodList",payMothodList);
        return AjaxResult.success(map);
    }

    /**
     * 查询付款计划列表
     */
    @PreAuthorize(hasPermi = "finance:paymentplan:list")
    @GetMapping("/list")
    public TableDataInfo list(CwPaymentPlanDto cwPaymentPlanDto)
    {
        startPage();
        List<ResponsePayManageDto> list = cwPaymentPlanService.getPaymentPlanList(cwPaymentPlanDto);
        return getDataTable(list);
    }


}
